<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8" />
<title>订单管理 - 查看订单</title>
<?php include($this->c['_homes']['_viewsHome'].'/_global/_head.php');?>
</head>
<!-- BEGIN BODY -->
<body class="page-header-fixed page-sidebar-fixed">
<!-- BEGIN HEADER -->
<?php include($this->c['_homes']['_viewsHome'].'/_global/head.php');?>
<!-- END HEADER -->
<div class="clearfix"></div>
<!-- BEGIN CONTAINER -->
<div class="page-container" > 
  <!-- BEGIN HORIZONTAL MENU PAGE SIDEBAR1 -->
  <?php include($this->c['_homes']['_viewsHome'].'/_global/menu.php');?>
  <!-- END BEGIN HORIZONTAL MENU PAGE SIDEBAR --> 
  <!-- BEGIN PAGE -->
  <div class="page-content"> 
    <!-- BEGIN PAGE HEADER-->
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title"> 查看订单 </h3>
        <ul class="page-breadcrumb breadcrumb">
          <li> <i class="icon-home"></i> <a href="/manage">后台</a> <i class="icon-angle-right"></i> </li>
          <li> 订单管理 <i class="icon-angle-right"></i> </li>
          <li> <a href="/order/olist">订单列表</a> <i class="icon-angle-right"></i> </li>
          <li>查看订单</li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB--> 
      </div>
    </div>
    <!-- END PAGE HEADER--> 
    <!-- BEGIN PAGE CONTENT-->
    
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN SAMPLE FORM PORTLET-->
        <form class="form-horizontal" id="_frm" method="post" action="/order/save" onSubmit="return chkfrm();">
          <input type="hidden" name="act" id="_act" value="">
          <input type="hidden" name="order_id" value="<?=$this->data['order_id'];?>">
          <input type="hidden" name="ref" value="<?=$_SERVER['HTTP_REFERER'];?>">
          <div class="tabbable tabbable-custom boxless">
          <div class="tab-content"> 
            <!--Tab0-->            
            <div class="tab-pane active" id="tab_1">
              <div class="portlet box blue ">
                <div class="portlet-title">
                  <div class="caption"> <i class="icon-reorder"></i> 商品信息 </div>
                </div>
                <div class="portlet-body">
                  <div class="table-scrollable">
                     <table class="table table-striped table-bordered table-hover dataTable">
                              <thead>
                                <tr>
                                  <th>商品ID</th>
                                  <th>商品名称</th>
                                  <th>商品规格</th>
                                  <th>商品图片</th>
                                  <th>商品条形码</th>                                  
                                  <th>供应商</th>
                                  <th>快递单号</th>
                                  <th>快递公司</th>
                                  <th>发货状态</th>
                                  <th>退款状态</th>
                                  <th>退货状态</th>                                  
                                  <th>零售单价</th>
                                  <th>硒米价格</th>
                                  <th>抵用代金券</th>
                                  <th>赠送商品票</th>
                                  <th>赠送代金券</th>
                                  <th>数量</th>
                                  <th>合计</th>
                                  <th>操作</th>
                                </tr>
                              </thead>
                              <tbody>
                                <?php
                								if($this->data['goods'])
                								{
                									foreach($this->data['goods'] as $k=> $r){																				
                								?>
                                <tr>
                                  <td><?=$r['goods_id'];?></td>
                                  <td><?=$r['goods_name'];?></td>
                                  <td><?=$r['attr_str'];?></td>
                                  <td>                                    
                                <?php if ($r['thumb_docid']):?>
                                    <img src="<?=$r['thumb_docid']?>" width="60"/>
                                <?php else: ?>
                                    <img src="<?=$r['pic_docid']?>" width="60" />
                                <?php endif;?>
                                </td>                                  
                                  <td><?=$r['goods_barcode'];?></td>                                  
                                  <td> 
                                      <select name="supplierid" class="form-control _supplierid" data-id="<?=$r['supplierid']; ?>" data-rid="<?=$r['rec_id']; ?>" style="width:200px;">
                                        <option value="">请选择供应商</option>
                                <?php
                  							if($this->supplier){
                  								foreach($this->supplier as $v){
                  								    
                  									if($r['supplierid']==$v['id']) $slk=' selected';
                  									else $slk = '';
                  								?>
                                              <option value="<?=$v['id'];?>"<?=$slk;?>>
                                              <?=$v['supplier'];?>
                                              </option>
                                       
                                              <?php
                  									
                  								}
                  							}							
                  							?></select>                                      
                                 </td>
                                  <td><?=$r['shipping_id'];?> </td>
                                  <td><?=$r['shipping_name'];?></td>
                                  <td><?=$this->c['stat']['order_show']['shipping'][ $r['shipping_status'] ];?></td>
                                  <td><?=$this->c['stat']['order_show']['refund_status'][ $r['refund_status'] ];?></td>
                                  <td><?=$this->c['stat']['order_show']['return_goods_status'][ $r['return_goods_status'] ];?></td>  
                                  <td>￥<?=$r['goods_price'];?></td>
                                  <td><?=$r['ximi_price'];?></td>
                                  <td><?=$r['coupon_price'];?></td>
                                  <td><?=$r['give_ticket'];?></td>                                
                                  <td><?=$r['give_coupon'];?></td>
                                  <td><?=$r['goods_number'];?></td>                                  
                                  <td>￥<?=number_format($r['goods_number']*$r['goods_price'],2,".","");?></td>
                                <td>
                                <?php if($this->data['pay_status']){
                                  if($r['shipping_id'] && $r['shipping_status']>0){
                                ?>
                                <a class="btn blue" href="/order/courier?id=<?=$r['shipping_id']?>&type=<?=$r['shipping_name']?>" >查看物流</a>
                                 <a class="btn blue" href="javascript:_receive_order(<?=$r['rec_id']?>)" >确认收货</a>
                                <?php 
                                  }
                                ?>
                                <?php if($r['return_goods_status']==1 || $r['return_goods_status']==4 || $r['return_goods_status']==3){ ?>
                              <!--  <a class="btn blue" href="/order/return_edit?rec_id=<?/*=$r['rec_id']*/?>&order_id=<?/*=$this->data['order_id'];*/?>" >申请退货</a>-->
                                <?php }  ?>
                                <?php if($r['refund_status']==1){ ?>
                              <!--   <a class="btn blue" href="/order/reimburse_edit?rec_id=<?/*=$r['rec_id']*/?>&order_id=<?/*=$this->data['order_id'];*/?>" >申请退款</a>-->
                                <?php }?>
                                <a class="btn blue" href="/order/shipping_edit?rec_id=<?=$r['rec_id']?>" >去发货</a>
                                <?php  } ?>
                                </td>
                                </tr>
                                <?php 
                                  }
                								}
                								?>
                                <tr>
                                <td colspan="16"></td>
                                <td>￥<?=$this->data['goods_amount'];?></td>
                                <td></td>
                                </tr>                                
                              </tbody>
                            </table>
                  </div>
                </div>
              </div>
            </div>
            <!--Tab1-->
            <div class="tab-pane active" id="tab_0">
              <div class="portlet box blue ">
                <div class="portlet-title">
                  <div class="caption"> <i class="icon-reorder"></i> 基本信息 </div>
                </div>
                <div class="portlet-body form">
                  <div class="form-body">
                    <div class="form-group">
                      <label  class="col-md-2 control-label">订单编号</label>
                      <div class="col-md-9">
                        <h5>
                          <?=$this->data['order_sn'];?>
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">创建时间</label>
                      <div class="col-md-9">
                        <h5>
                          <?=date("Y-m-d H:i:s",$this->data['add_time']);?>
                        </h5>
                      </div>
                    </div>
                    <hr>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">订单金额</label>
                      <div class="col-md-9">
                        <h5>￥
                          <?=$this->data['order_amount'];?>
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">商品金额</label>
                      <div class="col-md-9">
                        <h5>￥
                          <?=$this->data['goods_amount'];?>
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">运费金额</label>
                      <div class="col-md-9">
                        <h5>￥
                          <?=$this->data['shipping_fee'];?>
                        </h5>
                      </div>
                    </div>                  
                    <hr>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">优惠券抵用</label>
                      <div class="col-md-9">
                        <h5>
                          ￥<?=$this->data['discount_fee'];?>
                        </h5>
                      </div>
                    </div>
                     <div class="form-group">
                      <label  class="col-md-2 control-label">金花抵用</label>
                      <div class="col-md-9">
                        <h5>
                          ￥<?=$this->data['gold_fee'];?>
                        </h5>
                      </div>
                    </div> 
                    
                     <div class="form-group">
                      <label  class="col-md-2 control-label">代金券抵用</label>
                      <div class="col-md-9">
                        <h5>
                          ￥<?=$this->data['coupon_fee'];?>
                        </h5>
                      </div>
                    </div> 
                    <div class="form-group">
                      <label  class="col-md-2 control-label">硒米消费</label>
                      <div class="col-md-9">
                        <h5>
                          <?=($this->data['ximi_fee']*1);?>
                        </h5>
                      </div>
                    </div>
                    <hr>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">现金支付金额</label>
                      <div class="col-md-9">
                        <h4>￥<?=$this->data['pay_fee'];?></h4>
                      </div>
                    </div>
                    <hr>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">订单状态</label>
                      <div class="col-md-9">
                        <h5>
                          <?=$this->c['stat']['order_show']['status'][ $this->data['order_status'] ];?>
                        </h5>
                      </div>
                    </div>
                    
                    <div class="form-group">
                      <label  class="col-md-2 control-label">发货状态</label>
                      <div class="col-md-9">
                        <h5>
                          <?=$this->c['stat']['order_show']['shipping'][ $this->data['shipping_status'] ];?>
                        </h5>

                      </div>
                    </div>

                    <div class="form-group">
                      <label  class="col-md-2 control-label">付款状态</label>
                      <div class="col-md-9">
                        <h5>
                          <?=$this->c['stat']['order_show']['pay'][ $this->data['pay_status'] ];?>
                        </h5>
                        <?php
            						if($this->data['pay_status']>=2){
            							echo '<strong>付款时间</strong>：'.date("Y-m-d H:i:s",$this->data['pay_time']).'<br>
                          <strong>付款渠道 </strong>： '.$this->c['stat']['order_show']['transaction_type'][$this->data['transaction_type']].'<br>
            							<strong>微信支付流水号</strong>：'.$this->data['pay_transaction_id'].' ';
            						}					
            						?>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">销售类型</label>
                      <div class="col-md-9">
                        <h5>
                          <?=$this->c['stat']['order']['sell_type'][$this->data['sell_type']];?>
                        </h5>
                      </div>
                    </div>
                    <?php if($this->data['sell_type']==2 && $this->data['pick_up_status']!=0 ){ ?>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">自提状态</label>
                      <div class="col-md-9">
                        <h5>
                          <?=$this->c['stat']['order']['pick_up_status'][$this->data['pick_up_status']];?>
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">自提时间</label>
                      <div class="col-md-9">
                        <h5>
                          <?= empty($this->data['pick_up_time']) ?'':date("Y-m-d H:i",$this->data['pick_up_time']);?>
                        </h5>
                      </div>
                    </div>
                  <?php } ?>
                    <hr>
                    <?php if($this->pv['consignee']){?>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">收货人</label>
                      <div class="col-md-6">
                        <h5>
                           <input type="text" name="consignee" id="_consignee"  maxlength="40" class="form-control"  placeholder="请输入收货人" value="<?=$this->data['consignee'];?>">
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">联系电话</label>
                      <div class="col-md-6">
                        <h5>
                          <input type="text" name="mobile" id="_mobile"  maxlength="40" class="form-control"  placeholder="请输入联系电话" value="<?=$this->data['mobile'];?>">
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                              <label  class="col-md-2 control-label">修改收货地址</label>
                              <div class="col-md-2 item-slt">
                                <select id="_province_id" name="province_id" class="form-control">
                                <option value="">省份</option>
                                <?php foreach ($this->province as $region_id => $region_name) {?>
                                <option value="<?=$region_id?>" <?php if ($region_id == $this->data['province_id']): ?>selected="selected"<?php endif;?>><?=$region_name?></option>
                               <?php }?>
                              </select>

                              </div>
                              <div class="col-md-2 item-slt">
                              <select id="_city_id" name="city_id" class="form-control">
                        <option value="">市/区</option>
                        <?php
          foreach ($this->data['city_list'] as $region_id => $region_name) {?>
                           <option value="<?=$region_id?>" <?php if ($region_id == $this->data['city_id']): ?>selected="selected"<?php endif;?>><?=$region_name?></option>
                         <?php }?>
                      </select>
                              </div>
                              <div class="col-md-2 item-slt">
                              <select id="_county_id" name="county_id" class="form-control">
                        <option value="">县/区</option>
                        <?php
          foreach ($this->data['county_list'] as $region_id => $region_name) {?>
                          <option value="<?=$region_id?>" <?php if ($region_id == $this->data['county_id']): ?>selected="selected"<?php endif;?>><?=$region_name?></option>
                           <?php }?>
                      </select>
                    </div>

                  </div>
                  <div class="form-group">
                    <label  class="col-md-2 control-label"></label>
                    <div class="col-md-4">
                       <input type="text"  name="address" id="i_address" value="<?=$this->data['address']?>" class="form-control" placeholder="详细地址">
                    </div>
                  </div>

                    <div class="form-group">
                      <label  class="col-md-2 control-label">身份证号码</label>
                      <div class="col-md-6">
                        <h5>
                          <input type="text" name="idnum" id="_idnum"  maxlength="40" class="form-control"  placeholder="请输入身份证号码" value="<?=$this->data['idnum'];?>">
                          
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">客户备注</label>
                      <div class="col-md-6">
                        <h5>
                          <?=stripslashes($this->data['remark']);?>
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                    <label  class="col-md-2 control-label"></label>
                    <div class="col-md-3">
                        <button type="button" class="btn blue" onclick ="_shart()">修改</button>
                    </div>
                  </div>
                    <?php } else{ ?>
                        <div class="form-group">
                      <label  class="col-md-2 control-label">收货人</label>
                      <div class="col-md-6">
                        <h5>
                          <?=$this->data['consignee'];?>
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">联系电话</label>
                      <div class="col-md-6">
                        <h5>
                          <?=$this->data['mobile'];?>
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">收货地址</label>
                      <div class="col-md-6">
                        <h5>
                          <?php
                          if($this->data['province_id']>0) echo $this->data['region'][$this->data['province_id']];
                          if($this->data['city_id']>0) echo $this->data['region'][$this->data['city_id']];
                          if($this->data['county_id']>0) echo $this->data['region'][$this->data['county_id']];
                          echo $this->data['address'];
                          ?>
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">身份证号码</label>
                      <div class="col-md-6">
                        <h5>
                          <?=$this->data['idnum'];?>
                        </h5>
                      </div>
                    </div>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">客户备注</label>
                      <div class="col-md-6">
                        <h5>
                          <?=stripslashes($this->data['remark']);?>
                        </h5>
                      </div>
                    </div>

                    <?php } ?>
                  </div>
                </div>
              </div>
            </div>
            <!--Tab2-->
            <div class="tab-pane active" id="tab_2">
              <div class="portlet box blue ">
                <div class="portlet-title">
                  <div class="caption"> <i class="icon-reorder"></i> 订单操作</div>
                </div>
                <div class="portlet-body form">
                  <div class="form-body">
              
           
                    <hr>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">可执行操作</label>
                      <div class="col-md-9">
                        <!-- <button class="btn yellow" onClick="_set_act('unpay');">设为未付款</button> -->
                        <!--<button class="btn green" onClick="_set_act('payed');">设为已付款</button>-->
                        <!-- <button class="btn green" onClick="_checkPay();">检查是否已付款</button> -->
                       
                        <!-- <button class="btn green" onClick="_set_act('received');">设为已收货</button>
                        <button class="btn green" onClick="_set_act('done');">交易完成</button>
                        <button class="btn red" onClick="_set_act('cancel');">取消订单</button> -->
                      </div>
                    </div>
                    <hr>
                      <?php if($this->data['pay_status']==3){
                       ?>

                    <div class="form-group">
                      <label  class="col-md-2 control-label">退款退货操作</label>
                      <div class="col-md-9">
                        <button class="btn green" onClick="_set_act('refund');">设为已退款</button>
                          <button class="btn red" onClick="_set_act('refund_turn');">设为退款驳回</button>
                      </div>
                    </div>

                      <?php
                      }
                      ?>
                    <hr>
                    <div class="form-group">
                      <label  class="col-md-2 control-label">操作日志</label>
                      <div class="col-md-9">
                        <div class="table-scrollable">
             <table class="table table-striped table-bordered table-hover dataTable">
                            <thead>
                              <tr>
                                <th>操作者</th>
                                <th>日期</th>
                                <th>状态</th>
                                <th>备注</th>
                              </tr>
                            </thead>
                            <tbody>
                            <?php
              							if($this->logs['data']){
              								foreach($this->logs['data'] as $r){
              							?>
                                          <tr>
                                              <td><?=$this->logs['staff'][$r['staffid']];?></td>
                                              <td><?=date("Y-m-d H:i",$r['create_time']);?></td>
                                              <td><?=$r['status'];?></td>
                                              <td><?=$r['note'];?></td>
                                            </tr>
                                          <?
              								}
              							}
              							?>                            
                            </tbody>
                          </table>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <!--End Tab--> 
            </div>
          </div>
          
        </form>
        <!-- END SAMPLE FORM PORTLET--> 
      </div>
    </div>
    <!-- END PAGE CONTENT--> 
  </div>
  <!-- END PAGE --> 
</div>
<!-- END CONTAINER -->
<?php include($this->c['_homes']['_viewsHome'].'/_global/_footer.php');?>
<script>
jQuery(document).ready(function() {    
   App.init();	
});

function _set_act(act)
{

	$("#_act").prop("value",act);
	
}

function _checkPay(){
	$.post("/order/ajax",{
	"act":"checkpay",
	"order_id":	<?=$this->data['order_id'];?>,
	"mr":Math.random()
	},function(msg){
		var json = eval("("+msg+")");
		if(json.code==200){
			alert("支付已成功！");
			window.location.reload();	
		}
		else if(json.code==813){
			alert("未支付");	
		}
		else{
			alert("检测失败，错误代码["+json.code+"]");	
		}
	});	
}

function _shart()
{
  var provinceid=$('#_province_id').val();
  var cityid=$('#_city_id').val();
  var contryid=$('#_county_id').val();
  var address=$('#i_address').val();
  var consignee=$('#_consignee').val();
  var mobile=$('#_mobile').val();
  var idnum=$('#_idnum').val();
  if(cityid<=0){
    swal("请选择城市");
    return;
  }
  if($('#_county_id').children().length-1>0){
    if(contryid<=0){
    swal('请选择区域');
    return ;
    }
  }
  $.post("ajax",{
      "act":"province",
      "parent_id":parseInt(provinceid),"city_id":parseInt(cityid),"county_id":parseInt(contryid),"i_address":address,"consignee":consignee,"mobile":mobile,"idnum":idnum,"order_id": <?=$this->data['order_id'];?>,
      "mr":Math.random()
    },function(msg){
      if(msg!=""){
        var json = eval("("+msg+")");
        if(json.code==200){
           swal("修改成功！",false,"success");
        }else{
          swal("修改失败！");
        }
      }
    });
}


function chkfrm()
{
	var _act = $("#_act").prop("value"),cm = false;
	
	switch(_act){
		case "shipping":

      if( $("#_shipping_name").prop("value")==""){
        alert("请填写快递名称");
        $("#_shipping_name").focus();
        return false; 
      }

			if( $("#_shipping_id").prop("value")==""){
				alert("请填写快递单号");
				$("#_shipping_id").focus();
				return false;	
			}
			
			cm = confirm("确定发货？");
			break;
		
		case "received":
      cm = confirm("确定设为已收货？");
      break;
    case "refund":
    cm = confirm("确定设为已退款？");
    break;
    case "refund_turn":
        cm = confirm("确定设为已退款驳回？");
        break;
		case "done":
			cm = confirm("确定设为交易完成？");
			break;		
	}
	
	if(!cm) return false;
}
//确认收货
function _receive_order(rec_id)
{
  if( rec_id>0){
      if(confirm("确定设置为已收货吗？")){
            
          $.post("ajax",{
              "act":"receive_order",
              "rec_id":rec_id,"order_id": <?=$this->data['order_id'];?>,
              "mr":Math.random()
            },function(data){
              if(data!=""){
              
                if(data.code==200){
                  swal(data.msg,false,"success");
                  setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
                     window.location.reload();//页面刷新
                     },2000);
                }else{
                  swal(data.msg);
                }
              }
            },'json');
        
        }

  }
}
//修改市场价
$("._purchase_price").blur(function(){
    var price = Math.floor($(this).attr('data-val'));
  
	var rec_id = $(this).attr('data-id');
	var purchase_price = $(this).val();
	var p = $(this);
 	if(price != purchase_price){
        $.ajax({type:'POST',url:"ajax",dataType:'json',data:{"rec_id":rec_id,"act":"ajax_purchase_price","purchase_price":purchase_price}, success: function(data) {
            if(data.code==200){
              
            	 p.attr('data-val',purchase_price);
           	     swal(data.msg,false,"success");
             	
             }else{
           	 
           	  swal(data.msg+"["+data.code+"]",false,"error");
             }    
   		} 
   	
    })
	}	
});

$("._supplierid").change(function(){

    var supplierid = parseInt($(this).val());
    var rec_id = parseInt($(this).attr('data-rid'));
	var sid  = parseInt($(this).attr('data-id'));
        $.ajax({type:'POST',url:"ajax",dataType:'json',data:{"rec_id":rec_id,"act":"ajax_supplierid","supplierid":supplierid}, success: function(data) {
            if(data.code==200){
              
            	
           	     swal(data.msg,false,"success");
             	
             }else{
           	 
           	  swal(data.msg+"["+data.code+"]",false,"error");
             }    
   		} 
   	
    })
	
	
})
</script> 
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>